﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CheatManager : Singleton<CheatManager>
{
	bool isShow = false;
	Dictionary<UICamera, LayerMask> m_EventMask = new Dictionary<UICamera, LayerMask>();

	public void Hide()
	{
		isShow = false;

		foreach (KeyValuePair<UICamera, LayerMask> mask in m_EventMask)
		{
			if (mask.Key != null)
			{
				mask.Key.eventReceiverMask = mask.Value;
			}
		}

		m_EventMask.Clear();
	}
	
	public void Show()
	{
		isShow = true;

		foreach( Camera tCam in Camera.allCameras )
		{
			UICamera uiCam = tCam.GetComponent<UICamera>();
			if( uiCam )
			{
				m_EventMask.Add( uiCam, uiCam.eventReceiverMask );
				uiCam.eventReceiverMask = 0;
			}
		}
	}
	
	void OnGUI()
	{
		if (!isShow)
			return;

		if ( GUI.Button(ResizeGUI(new Rect(100, 100, 180, 180)), "Close") )
			Hide();


		if ( GUI.Button(ResizeGUI(new Rect(500, 100, 180, 180)), "Cheat 1") )
			EPLog.Log ("Cheat 1");

		if ( GUI.Button(ResizeGUI(new Rect(500, 300, 180, 180)), "Cheat 2") )
			EPLog.Log ("Cheat 2");

		if ( GUI.Button(ResizeGUI(new Rect(500, 500, 180, 180)), "Cheat 3") )
			EPLog.Log ("Cheat 3");

		if ( GUI.Button(ResizeGUI(new Rect(500, 700, 180, 180)), "Cheat 4") )
			EPLog.Log ("Cheat 4");

		if ( GUI.Button(ResizeGUI(new Rect(700, 100, 180, 180)), "Cheat 5") )
			EPLog.Log ("Cheat 5");

		if ( GUI.Button(ResizeGUI(new Rect(700, 300, 180, 180)), "Cheat 6") )
			EPLog.Log ("Cheat 6");

		if ( GUI.Button(ResizeGUI(new Rect(700, 500, 180, 180)), "Cheat 7") )
			EPLog.Log ("Cheat 7");

		if ( GUI.Button(ResizeGUI(new Rect(700, 700, 180, 180)), "Cheat 8") )
			EPLog.Log ("Cheat 8");


	}
	
	Rect ResizeGUI(Rect _rect)
	{
		float FilScreenWidth = _rect.width / 1920;
		float rectWidth = FilScreenWidth * Screen.width;
		float FilScreenHeight = _rect.height / 1080;
		float rectHeight = FilScreenHeight * Screen.height;
		float rectX = (_rect.x / 1920) * Screen.width;
		float rectY = (_rect.y / 1080) * Screen.height;
		return new Rect(rectX,rectY,rectWidth,rectHeight);
	}

}
